﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Rewrite;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection;

namespace Microsoft.AspNetCore.Mvc.Routing
{
    /// <summary>
    /// Represents a URL rewriting rule, which both applies to inbound url rewriting
    /// and outbound url generation.
    /// </summary>
    /// <remarks>
    /// <para>
    /// Note that this object will be used as a <see cref="ServiceLifetime.Singleton"/>
    /// service, so the implementation should be thread-safe.
    /// </para>
    /// <para>
    /// If you want to fully suppress the <see cref="IUrlHelper"/> to rewrite outbound urls,
    /// you can set <see cref="HttpContext.Items"/> with key <c>__SuppressOutboundRewriting</c>.
    /// </para>
    /// </remarks>
    public interface IRewriteRule : IRule
    {
        /// <summary>
        /// Apply the rules on the path segment generated by <see cref="LinkGenerator"/>.
        /// </summary>
        /// <param name="context">The action context.</param>
        /// <param name="path">The path to modify.</param>
        /// <returns>Whether to continue url modifying.</returns>
        /// <remarks>
        /// <para>
        /// Note that implementation should be light-weight enough so that
        /// the performance wouldn't be affected.
        /// </para>
        /// <para>
        /// You can disable this feature fully by setting <see cref="HttpContext.Items"/>
        /// with key <c>__SuppressOutboundRewriting</c> and value of anything.
        /// </para>
        /// </remarks>
        RuleResult ApplyUrl(ActionContext context, ref string path);
    }
}
